package com.space.domain.core;

import com.space.components.domain.core.Aggregate;
import com.space.domain.core.entity.UserId;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @author <a href="mailto:414563035@qq.com">Bedroom</a>
 * @date 2021/6/2 5:48 下午
 */
@NoArgsConstructor
public class User extends Aggregate<UserId> {
    private UserId userId;

    private List<User> children = new ArrayList<>();

    String name;

    @Override
    public String toString() {
        return "User{" +
                "userId=" + userId +
                ", children=" + children +
                ", name='" + name + '\'' +
                '}';
    }

    public User(Integer userId) {
        this.userId = new UserId(userId);
        this.name = "Xin";
        initSnapshot();
    }

    public void changeName(String newName) {
        this.name = newName;
    }

    public void setChildren(User child) {
        this.children.add(child);
    }

    @Override
    public UserId getIdentifier() {
        return userId;
    }

}
